﻿using BG.DAL.Model;
using BG.DAL.Context;
using System.Collections.Generic;
using System;
using System.Data;
using System.Data.Entity;
using System.Linq;

namespace BG.DAL.SQLDAL
{
    public class CompanyManager
    {
        public static List<Company> GetAll()
        {
            using (DataContext db = new DataContext())
            {
                return db.Companies.ToList();
            }
        }


        public static Company GetById(Guid id)
        {
            using (DataContext db = new DataContext())
            {
                Company model = db.Companies.Find(id);
                return model;
            }
        }

        public static void Create(Company model)
        {
            using (DataContext db = new DataContext())
            {
                db.Companies.Add(model);
                db.SaveChanges();
            }
        }

        public static void Edit(Company model)
        {
            using (DataContext db = new DataContext())
            {
                db.Entry(model).State = EntityState.Modified;
                db.SaveChanges();
            }
        }

        public static void Delete(Guid id)
        {
            using (DataContext db = new DataContext())
            {
                Company model = db.Companies.Find(id);
                db.Companies.Remove(model);
                db.SaveChanges();
            }
        }
    }
}
